/*
 * Copyright (C) 2023  即时通讯网(52im.net) & Jack Jiang.
 * The MobileIMSDK-Uniapp客户端 Project. All rights reserved.
 *
 * 【本产品为著作权产品，请在授权范围内放心使用，禁止外传！】
 *
 * 【本系列产品在国家版权局的著作权登记信息如下】：
 * 1）国家版权局登记名（简称）和证书号：RainbowChat（软著登字第1220494号）
 * 2）国家版权局登记名（简称）和证书号：RainbowChat-Web（软著登字第3743440号）
 * 3）国家版权局登记名（简称）和证书号：RainbowAV（软著登字第2262004号）
 * 4）国家版权局登记名（简称）和证书号：MobileIMSDK-Web（软著登字第2262073号）
 * 5）国家版权局登记名（简称）和证书号：MobileIMSDK（软著登字第1220581号）
 * 著作权所有人：江顺/苏州网际时代信息科技有限公司
 *
 * 【违法或违规使用投诉和举报方式】：
 * 联系邮件：jack.jiang@52im.net
 * 联系微信：hellojackjiang
 * 联系QQ： 413980957
 * 官方社区：http://www.52im.net
 */
/**
 * 一个简单的事件总线实现类（通过此类实现SDK层与Page界面层的代码解偶）。
 * 
 * @author 来自网络 & JackJiang(http://www.52im.net/space-uid-1.html)
 */


// let DB = require("../../../util/sqlite/sqlite.js");

import {
	DB
} from '../../../util/sqlite/sqlite.js'



let audio = '';
const innerAudioContext = uni.createInnerAudioContext()

class EventBus {
	constructor() {}

	/**
	 * 注册事件接收者。
	 * 
	 * @param {*} type 
	 * @param {*} cb 
	 */
	register(type, cb) {
		if (type && cb) {
			uni.$on(type, cb);
		}
	}

	/**
	 * 取消注册事件接收者。
	 * 
	 * @param {*} type 
	 * @param {*} cb 
	 */
	unregister(type, cb) {
		if (type && cb) {
			uni.$off(type, cb);
		}
	}

	/**
	 * 发出事件。
	 * 
	 * @param {*} type 
	 * @param  {...any} args 
	 */
	post(type, obj) {
		if (type) {
			uni.$emit(type, obj);
			let p = obj
			console.log(p);
			console.log(type);

			// || p.typeu == 12
			// ////3一对一聊天45群聊天7添加好友10已添加12拒绝46、加群47指定群员48群已被解散49"你"被踢出群聊50"别人"主动退出或被群主踢出群聊51群名被修改的系统通知
			// ////1上线2下线
			if (type == 'event2ui.onIMData' && p && p.typeu && (p.typeu == 1 || p.typeu == 2)) {
				
				let online_time = Math.floor(uni.MBUtils.getCurrentUTCTimestamp());;// uni.MBUtils.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss');
				
				let data = `online = 'true' ,online_time = '${online_time}'`;
				if(p.typeu == 2){
					data = `online = 'false',online_time = '${online_time}'`;
				}
				let where = `user_uid = '${p.dataContent}'`
				// 修改表数据 DB.updateTableData(表名, 要修改的列名=修改后列值, 修改条件的列名, 修改条件的列值)
				DB.updateTableData("friend" + uni.getStorageSync("user_uid"), data, where)
					.then(res => {
						
					})
					.catch(error => {
						console.log("修改失败", error);
					});
			
			}else if (type == 'event2ui.onIMData' && p && p.typeu && p.typeu == 43) {
				let dataContent = JSON.parse(p.dataContent);
				console.log(dataContent)
				let type = '';
				
				if (dataContent.f != 10000)  {
					this.openSQL();

					let open = DB.isOpen();
					if (open) {
						let arr = []
						let update_data = JSON.parse(p.dataContent);
						console.log(update_data);
						arr.push(p)
						arr.map(item => {


							let time = uni.MBUtils.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss');
							let sm = 0;
							if (item.sm) {
								sm = item.sm;
							}
							let dataContent = JSON.parse(item.dataContent);

							let chat_type = dataContent.ty

							let gid = 0;
							if (p.typeu == 45 || p.typeu == 47 || p.typeu == 50 || p.typeu == 49 || p
								.typeu ==
								48) {
								gid = JSON.parse(item.dataContent).t;

								chat_type = 90;
							} else if (p.typeu == 46) {
								gid = JSON.parse(item.dataContent).g_id;
								chat_type = 90;
							} else if (p.typeu == 51) {
								gid = JSON.parse(item.dataContent).gid;
								chat_type = 90;
							}
							if (p.typeu == 10) {
								gid = 0;
								chat_type = 90;
								item.from = JSON.parse(item.dataContent).user_uid;
							}

							console.log(chat_type);

							if (dataContent.ty == 30) {
								console.log(dataContent);
								// this.getmessage(dataContent.f,dataContent.t);

							} else if (dataContent.ty == 91) {

								update_data.m = '消息撤回';
								let update_data_str = JSON.stringify(update_data);
								let data = `dataContent = '${update_data_str}'`;

								if (dataContent.m.indexOf('fpForMessage') >= 0) {
									let m = JSON.parse(dataContent.m)
									console.log(m.fpForMessage);

									let where = `fp = '${m.fpForMessage}'`
									// 修改表数据 DB.updateTableData(表名, 要修改的列名=修改后列值, 修改条件的列名, 修改条件的列值)
									DB.updateTableData("chat" + uni.getStorageSync("user_uid"), data, where)
										.then(res => {

										})
										.catch(error => {
											console.log("修改失败", error);
										});
								}

							} else if (dataContent.ty == 13 || dataContent.ty == 14) {
								let m_z = JSON.parse(dataContent.m);
								m_z.receivetime = uni.MBUtils.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss');
								m_z.is_receive = 1;

								if (dataContent.ty == 13) {
									update_data.ty = 10;
								} else {
									update_data.ty = 12;
								}

								let where = `(fp = '${m_z.fp}')`
								update_data.m = JSON.stringify(m_z);
								let update_data_str = JSON.stringify(update_data);
								let data = `dataContent = '${update_data_str}'`;
								DB.updateTableData("chat" + uni.getStorageSync("user_uid"), data, where)
									.then(res => {

									})
									.catch(error => {
										console.log("修改失败", error);
									});
							} else if (dataContent.ty == 20) {


								let m_z = dataContent.m; //JSON.parse(dataContent.m);

								let where = `(fp = '${m_z.fp}')`

								let data = `is_read = 1`;
								DB.updateTableData("chat" + uni.getStorageSync("user_uid"), data, where)
									.then(res => {

									})
									.catch(error => {
										console.log("修改失败", error);
									});
							} else {

								if (dataContent.ty == 31) {
									console.log(p)
									console.log(dataContent)
								}

								let relatedId = '';
								if (!gid || gid == '0') {
									if (item.from == uni.getStorageSync('user_uid')) {
										relatedId = item.to;
									} else {
										// relatedId = item.from;
										if (item.from && item.from != 0) {
											relatedId = item.from;
										} else if (dataContent.user_uid && dataContent.user_uid != 0) {
											relatedId = dataContent.user_uid;
										} else {
											relatedId = 0;
										}
									}


								} else {
									relatedId = gid;
								}

								if (p.typeu == 7) {
									relatedId = '0';
								}


								let disturbhashMap = uni.getStorageSync('disturbhashMap' + uni
									.getStorageSync(
										"user_uid"));
								let tophashMap = uni.getStorageSync('tophashMap' + uni.getStorageSync(
									"user_uid"));

								let is_top = 0;
								let is_mute = 0;
								if (disturbhashMap) {
									disturbhashMap = new Map(JSON.parse(disturbhashMap));
									is_mute = disturbhashMap.get(relatedId) ?? false;
									is_mute = Number(is_mute) ?? 0;
								}
								if (tophashMap) {
									tophashMap = new Map(JSON.parse(tophashMap));

									is_top = tophashMap.get(relatedId) ?? false;
									is_top = Number(is_top) ?? 0;
								}
								if (is_mute == 0) {
									uni.vibrateShort({
										success: () => {
											console.log('短时间震动完成');
										}
									});
									if (uni.getStorageSync('mp3') == 0) {
										console.log('playRingtone');
										this.playRingtone()
									}
								}
								let fp = item.fp;

								if (dataContent.parentFp) {
									fp = dataContent.parentFp;
								}
								console.log(dataContent)
								console.log(fp)
								
								let from = dataContent.f;
								let to = dataContent.t;
								




								let sql =
									`'${item.type}', '${item.dataContent}', '${from}', '${to}', '${item.QoS}', '${item.typeu}', '${sm}', '${fp}', '0', '${time}', '${gid}',0,0, '${chat_type}','${relatedId}',${is_top},${is_mute}`;
								console.log(sql, "-=-=-=-=-=sas")
								let condition =
									'type, dataContent, from1, to1, QoS, typeu, sm, fp, retryCount, time,gid,is_collect,del_flag,chat_type,relatedId,is_top,is_mute';
								// 新增 DB.insertTableData(表名, 对应表头列的数据)

								console.log('insertTableData4')

								// 如果需要根据p参数插入新数据，可以在这里正确处理p与arr的关系，例如arr.push(p)等操作


								DB.insertTableData("chat" + uni.getStorageSync("user_uid"), sql, condition)
									.then(res => {
										console.log("新增数据成功");
										// ////群解散或被踢出群
										if (p.typeu == 48 || p.typeu == 49) {
											// let m_z = dataContent.m; //JSON.parse(dataContent.m);

											// let where = `(gid = '${gid}')`

											// let data = `del_flag = 1`;
											// DB.updateTableData("chat" + uni.getStorageSync("user_uid"),
											// 		data, where)
											// 	.then(res => {

											// 	})
											// 	.catch(error => {
											// 		console.log("修改失败", error);
											// 	});
										}

									})
									.catch(error => {
										console.log("失败", error);
										if (error.code == '-1404') {
											this.createTable();

											this.insertTableData(p);
										}
									});
							}

							// console.log(time);


						})
					}
				}


			} else if (type == 'event2ui.onIMData' && p && (p.typeu == 3 || p.typeu == 45 || p.typeu == 7 || p
					.typeu ==
					10 || p.typeu == 11 || p.typeu == 46 || p.typeu == 47 || p.typeu == 48 || p
					.typeu == 49 || p.typeu == 50 || p.typeu == 51)) {



				this.openSQL();

				let open = DB.isOpen();
				if (open) {

					if (p.typeu == 7) {
						// console.log('p.typeu')
						let dataContent = JSON.parse(p.dataContent);
						let dataContent_z = JSON.parse(p.dataContent);


						let from = '';
						if (p.from && p.from != 0) {
							from = p.from
						} else if (dataContent_z.user_uid && dataContent_z.user_uid != 0) {
							from = dataContent_z.user_uid;
						} else {
							from = 0;
						}
						let where = `typeu = 7 and from1 = '${from}' and del_flag = 0`;
						// let where = `typeu = 7 and relatedId = '${from}' and del_flag = 0`;
						DB.selectTableDataNew("chat" + uni.getStorageSync("user_uid"), where)
							.then(res => {
								// console.log(res.length)
								if (res.length == 0) {
									let arr = []
									arr.push(p)
									// 如果需要根据p参数插入新数据，可以在这里正确处理p与arr的关系，例如arr.push(p)等操作

									arr.map(item => {
										console.log(item, 'arr-=-=-=-=-=arr-=-=-=-')
										let dataContent = JSON.parse(item.dataContent);
										let chat_type = dataContent.ty

										let time = p.time ?? uni.MBUtils.formatDate(new Date(),
											'yyyy-MM-dd hh:mm:ss');
										let sm = 0;
										if (item.sm) {
											sm = item.sm;
										}
										let gid = 0;
										let relatedId = '';
										relatedId = 0;
										let disturbhashMap = uni.getStorageSync('disturbhashMap' + uni
											.getStorageSync("user_uid"));
										let tophashMap = uni.getStorageSync('tophashMap' + uni
											.getStorageSync(
												"user_uid"));
										console.log(tophashMap);
										let is_top = 0;
										let is_mute = 0;
										if (disturbhashMap) {
											disturbhashMap = new Map(JSON.parse(disturbhashMap));
											is_mute = disturbhashMap.get(relatedId) ?? false;
											is_mute = Number(is_mute) ?? 0;
										}
										if (tophashMap) {
											console.log(tophashMap);
											console.log(is_top);
											tophashMap = new Map(JSON.parse(tophashMap));

											is_top = tophashMap.get(relatedId) ?? false;
											is_top = Number(is_top) ?? 0;
										}




										let sql =
											`'${item.type}', '${item.dataContent}', '${item.from}', '${item.to}', '${item.QoS}', '${item.typeu}', '${sm}', '${item.fp}', '0', '${time}', '${gid}',0,0, '${chat_type}','${relatedId}',${is_top},${is_mute}`;
										console.log(sql, "-=-=-=-=-=sas")
										// this.info
										let condition =
											'type, dataContent, from1, to1, QoS, typeu, sm, fp, retryCount, time,gid,is_collect,del_flag,chat_type,relatedId,is_top,is_mute';
										// 新增 DB.insertTableData(表名, 对应表头列的数据)

										console.log('insertTableData4')
										DB.insertTableData("chat" + uni.getStorageSync("user_uid"), sql,
												condition)
											.then(res => {
												console.log("新增数据成功");
											})
											.catch(error => {
												console.log("失败", error);
											});
									})
								}
							})
							.catch(error => {
								console.log("查询失败", error);
								if (String(error.code) == '-1404' || error.code == -1404) {
									console.log(error.code);
									this.createTable();
								}

							});
					} else {

						let arr = []
						let update_data = JSON.parse(p.dataContent);
						console.log(update_data);
						arr.push(p)
						arr.map(item => {


							let time = uni.MBUtils.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss');
							let sm = 0;
							if (item.sm) {
								sm = item.sm;
							}
							let dataContent = JSON.parse(item.dataContent);

							let chat_type = dataContent.ty

							let gid = 0;
							if (p.typeu == 45 || p.typeu == 47 || p.typeu == 50 || p.typeu == 49 || p
								.typeu ==
								48) {
								gid = JSON.parse(item.dataContent).t;

								chat_type = 90;
							} else if (p.typeu == 46) {
								gid = JSON.parse(item.dataContent).g_id;
								chat_type = 90;
							} else if (p.typeu == 51) {
								gid = JSON.parse(item.dataContent).gid;
								chat_type = 90;
							}
							if (p.typeu == 10) {
								gid = 0;
								chat_type = 90;
								item.from = JSON.parse(item.dataContent).user_uid;
							}

							console.log(chat_type);

							if (dataContent.ty == 30) {
								console.log(dataContent);
								// this.getmessage(dataContent.f,dataContent.t);

							} else if (dataContent.ty == 91) {

								update_data.m = '消息撤回';
								let update_data_str = JSON.stringify(update_data);
								let data = `dataContent = '${update_data_str}'`;

								if (dataContent.m.indexOf('fpForMessage') >= 0) {
									let m = JSON.parse(dataContent.m)
									console.log(m.fpForMessage);

									let where = `fp = '${m.fpForMessage}'`
									// 修改表数据 DB.updateTableData(表名, 要修改的列名=修改后列值, 修改条件的列名, 修改条件的列值)
									DB.updateTableData("chat" + uni.getStorageSync("user_uid"), data, where)
										.then(res => {

										})
										.catch(error => {
											console.log("修改失败", error);
										});
								}

							} else if (dataContent.ty == 13 || dataContent.ty == 14) {
								let m_z = JSON.parse(dataContent.m);
								m_z.receivetime = uni.MBUtils.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss');
								m_z.is_receive = 1;

								if (dataContent.ty == 13) {
									update_data.ty = 10;
								} else {
									update_data.ty = 12;
								}

								let where = `(fp = '${m_z.fp}')`
								update_data.m = JSON.stringify(m_z);
								let update_data_str = JSON.stringify(update_data);
								let data = `dataContent = '${update_data_str}'`;
								DB.updateTableData("chat" + uni.getStorageSync("user_uid"), data, where)
									.then(res => {

									})
									.catch(error => {
										console.log("修改失败", error);
									});
							} else if (dataContent.ty == 20) {


								let m_z = dataContent.m; //JSON.parse(dataContent.m);

								let where = `(fp = '${m_z.fp}')`

								let data = `is_read = 1`;
								DB.updateTableData("chat" + uni.getStorageSync("user_uid"), data, where)
									.then(res => {

									})
									.catch(error => {
										console.log("修改失败", error);
									});
							} else {

								if (dataContent.ty == 31) {
									console.log(p)
									console.log(dataContent)
								}

								let relatedId = '';
								if (!gid || gid == '0') {
									if (item.from == uni.getStorageSync('user_uid')) {
										relatedId = item.to;
									} else {
										// relatedId = item.from;
										if (item.from && item.from != 0) {
											relatedId = item.from;
										} else if (dataContent.user_uid && dataContent.user_uid != 0) {
											relatedId = dataContent.user_uid;
										} else {
											relatedId = 0;
										}
									}


								} else {
									relatedId = gid;
								}

								if (p.typeu == 7) {
									relatedId = '0';
								}


								let disturbhashMap = uni.getStorageSync('disturbhashMap' + uni
									.getStorageSync(
										"user_uid"));
								let tophashMap = uni.getStorageSync('tophashMap' + uni.getStorageSync(
									"user_uid"));

								let is_top = 0;
								let is_mute = 0;
								if (disturbhashMap) {
									disturbhashMap = new Map(JSON.parse(disturbhashMap));
									is_mute = disturbhashMap.get(relatedId) ?? false;
									is_mute = Number(is_mute) ?? 0;
								}
								if (tophashMap) {
									tophashMap = new Map(JSON.parse(tophashMap));

									is_top = tophashMap.get(relatedId) ?? false;
									is_top = Number(is_top) ?? 0;
								}
								if (is_mute == 0) {
									uni.vibrateShort({
										success: () => {
											console.log('短时间震动完成');
										}
									});
									if (uni.getStorageSync('mp3') == 0) {
										console.log('playRingtone');
										this.playRingtone()
									}
								}
								let fp = item.fp;

								if (dataContent.parentFp) {
									fp = dataContent.parentFp;
								}
								// console.log(dataContent)
								// console.log(fp)




								let sql =
									`'${item.type}', '${item.dataContent}', '${item.from}', '${item.to}', '${item.QoS}', '${item.typeu}', '${sm}', '${fp}', '0', '${time}', '${gid}',0,0, '${chat_type}','${relatedId}',${is_top},${is_mute}`;
								console.log(sql, "-=-=-=-=-=sas")
								let condition =
									'type, dataContent, from1, to1, QoS, typeu, sm, fp, retryCount, time,gid,is_collect,del_flag,chat_type,relatedId,is_top,is_mute';
								// 新增 DB.insertTableData(表名, 对应表头列的数据)

								// console.log('insertTableData4')

								// 如果需要根据p参数插入新数据，可以在这里正确处理p与arr的关系，例如arr.push(p)等操作


								DB.insertTableData("chat" + uni.getStorageSync("user_uid"), sql, condition)
									.then(res => {
										console.log("新增数据成功");

										if (p.typeu == 48) {
											let m_z = dataContent.m; //JSON.parse(dataContent.m);

											let where = `(gid = '${gid}')`

											let data = `del_flag = 1`;
											DB.updateTableData("chat" + uni.getStorageSync("user_uid"),
													data, where)
												.then(res => {

												})
												.catch(error => {
													console.log("修改失败", error);
												});
										}

									})
									.catch(error => {
										console.log("失败", error);
										if (error.code == '-1404') {
											this.createTable();

											this.insertTableData(p);
										}
									});
							}

							// console.log(time);


						})


					}
				}
			}
		}
	}
	

	openSQL() {
		// 这个是查询有没有打开数据库
		let open = DB.isOpen();
		console.log("数据库状态", open ? "开启" : "关闭");
		if (!open) {
			DB.openSqlite()
				.then(res => {
					console.log("数据库已打开");
				})
				.catch(error => {
					console.log("数据库开启失败");
				});
		}
	}

	// 关闭数据库
	closeSQL() {
		// 这个是查询有没有打开数据库
		let open = DB.isOpen();
		if (open) {
			DB.closeSqlite()
				.then(res => {
					console.log("数据库已关闭");
				})
				.catch(error => {
					console.log("数据库关闭失败");
				});
		}
	}
	// 创建表
	createTable() {
		let open = DB.isOpen();
		if (open) {
			this.openSQL();
			// 修改后的表结构定义语句，列名不用双引号括起来
			let sql =
				'id INTEGER PRIMARY KEY AUTOINCREMENT, type text, dataContent text, from1 text, to1 text, QoS text, typeu text, sm text, fp text, retryCount text DEFAULT 0, time text,nickname text,avatar text,is_read text DEFAULT 0,gid text,is_collect text DEFAULT 0,del_flag text DEFAULT 0,chat_type text,relatedId text,is_top INTEGER DEFAULT 0,is_mute INTEGER DEFAULT 0';
			// 创建表 DB.createTable(表名, 表的列)
			DB.createTable("chat" + uni.getStorageSync("user_uid"), sql)
				.then(res => {
					console.log("创建chat表成功", res);
				})
				.catch(error => {
					console.log("创建表失败", error);
				});
		} else {
			console.log("数据库未打开");
		}
	}
	// 新增表数据
	insertTableData(p) {
		console.log(p)
		let open = DB.isOpen();
		if (open) {
			let arr = []
			arr.push(p)
			// 如果需要根据p参数插入新数据，可以在这里正确处理p与arr的关系，例如arr.push(p)等操作

			arr.map(item => {
				console.log(item, 'arr-=-=-=-=-=arr-=-=-=-')

				let dataContent = JSON.parse(item.dataContent);

				let time = uni.MBUtils.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss');
				let sm = 0;
				if (item.sm) {
					sm = item.sm;
				}
				let chat_type = dataContent.ty
				let gid = 0;
				if (p.typeu == 45 || p.typeu == 47 || p.typeu == 50 || p.typeu == 49 || p.typeu ==
					48) {
					gid = JSON.parse(item.dataContent).t;

					chat_type = 90;
				} else if (p.typeu == 46) {
					gid = JSON.parse(item.dataContent).g_id;
					chat_type = 90;
				} else if (p.typeu == 51) {
					gid = JSON.parse(item.dataContent).gid;
					chat_type = 90;
				}
				if (p.typeu == 10) {
					gid = 0;
					chat_type = 90;
					item.from = JSON.parse(item.dataContent).user_uid;
				}

				let relatedId = '';
				if (!gid || gid == '0') {
					if (item.from == uni.getStorageSync('user_uid')) {
						relatedId = item.to;
					} else {
						relatedId = item.from;
					}
				} else {
					relatedId = gid;
				}
				if (p.typeu == 7) {
					relatedId = '0';
				}
				let disturbhashMap = uni.getStorageSync('disturbhashMap' + uni.getStorageSync("user_uid"));
				let tophashMap = uni.getStorageSync('tophashMap' + uni.getStorageSync("user_uid"));

				let is_top = 0;
				let is_mute = 0;
				if (disturbhashMap) {
					disturbhashMap = new Map(JSON.parse(disturbhashMap));
					is_mute = Number(disturbhashMap.get(relatedId)) ?? 0;
				}
				if (tophashMap) {
					tophashMap = new Map(JSON.parse(tophashMap));

					is_mute = Number(tophashMap.get(relatedId)) ?? 0;
				}

				console.log(relatedId);
				let sql =
					`'${item.type}', '${item.dataContent}', '${item.from}', '${item.to}', '${item.QoS}', '${item.typeu}', '${sm}', '${item.fp}', '0', '${time}', '${gid}',0,0, '${chat_type}','${relatedId}',${is_top},${is_mute}`;
				console.log(sql, "-=-=-=-=-=sas")
				let condition =
					'type, dataContent, from1, to1, QoS, typeu, sm, fp, retryCount, time,gid,is_collect,del_flag,chat_type,relatedId,is_top,is_mute';
				// 新增 DB.insertTableData(表名, 对应表头列的数据)


				console.log('insertTableData4')
				DB.insertTableData("chat" + uni.getStorageSync("user_uid"), sql, condition)
					.then(res => {
						console.log("新增数据成功");

					})
					.catch(error => {
						console.log("失败", error);
					});
			})


		} else {
			this.$util.toast("数据库未打开");
		}
	}


	initAudio() {
		if (!audio) {
			audio = uni.createInnerAudioContext();
			// audio.src = '../../../static/mp3/play.mp3'; // 本地铃声路径
			audio.src = '../../static/mp3/play.mp3'; // 本地铃声路径
			audio.loop = false; // 循环播放
			audio.volume = 1.0; // 设置音量
		}
	}
	// 播放铃声
	playRingtone() {
		this.initAudio();

		audio.play();
		console.log('铃声开始播放');
	}
	// 停止铃声
	stopRingtone() {
		if (audio) {
			audio.stop();
			console.log('铃声停止播放');
		}
	}

}

// 全局单例，方便使用
module.exports = new EventBus();